﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Gencode.Gengui.Display
{
	public partial class ViewSelectionHeader : UserControl
	{
		public event ListHeaderClieckEventHandler ListHeaderCliecked;

		public ViewSelectionHeader()
		{
			InitializeComponent();
		}

		string m_text = string.Empty;
		// The text to display inside the control.
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public override string Text
		{
			get
			{
				return (m_text);
			}
			set
			{
				m_text = value;
			}
		}

		string m_name = string.Empty;
		// The text to display inside the control.
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public string ControlName
		{
			get
			{
				return (m_name);
			}
			set
			{
				m_name = value;
			}
		}

		DisplayableViewControler _partnerView;
		public DisplayableViewControler PartnerView
		{
			get
			{
				return _partnerView;
			}
			set
			{
				_partnerView = value;
			}
		}

		/// <summary>
		/// image to be displayed in the header
		/// </summary>
		public Image Image
		{
			set
			{
				this.pictureBox1.Visible = true;
				this.pictureBox1.Image = value;
			}
		}

		Font m_font = new Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
		/// <summary>
		/// Font for text to display inside the control.
		/// </summary>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public override Font Font
		{
			get
			{
				return m_font;
			}
			set
			{
				m_font = value;
			}
		}

		Color _foreColor = Color.WhiteSmoke;
		public override Color ForeColor
		{
			get
			{
				return _foreColor;
			}
			set
			{
				_foreColor = value;
			}
		}

		private void ViewSelectionHeader_Paint(object sender, PaintEventArgs e)
		{
			//LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(219, 217, 200), Color.FromArgb(196, 193, 176), 90);
			//LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(219, 217, 200), Color.FromArgb(170, 159, 147), 90);
			//LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(170, 159, 147), Color.FromArgb(64, 64, 64), 90);
			LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(130, 130, 130), Color.FromArgb(30, 30, 30), 90);
			//LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(120, 120, 120), Color.FromArgb(30, 30, 30), 90);

			e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this.Width, this.Height));

			// Render the text next to the plus/minus box.
			int textOffsetX = pictureBox1.Location.X + pictureBox1.Width;
			RectangleF textRect = new RectangleF(textOffsetX + 4, 0, this.Width - (textOffsetX + 8), this.Height);
			StringFormat textFormat = new StringFormat();
			textFormat.Alignment = StringAlignment.Far;
			textFormat.LineAlignment = StringAlignment.Center;
			e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect, textFormat);
		}

		private void ViewSelectionHeader_Click(object sender, EventArgs e)
		{
			if (ListHeaderCliecked != null)
			{
				if (PartnerView.Visible)
					ListHeaderCliecked(this, new ListHeaderClickEventArgs("default"));
				else
					ListHeaderCliecked(this, new ListHeaderClickEventArgs(ControlName));
			}
		}

		private void pictureBox1_Click(object sender, EventArgs e)
		{
			if (ListHeaderCliecked != null)
			{
				if (PartnerView.Visible)
					ListHeaderCliecked(this, new ListHeaderClickEventArgs("default"));
				else
					ListHeaderCliecked(this, new ListHeaderClickEventArgs(ControlName));
			}
		}
	}

	public class ListHeaderClickEventArgs : EventArgs
	{
		private string _controlName;

		public ListHeaderClickEventArgs(string controlName)
			: base()
		{
			_controlName = controlName;
		}

		public string ControlName
		{
			get
			{
				return (_controlName);
			}
		}
	}

	public delegate void ListHeaderClieckEventHandler(object sender, ListHeaderClickEventArgs e);
}
